﻿<%@ WebHandler Language="C#" Class="BaseHandler" %>

using System;
using System.Web;
using Activity.API;

/// <summary>
/// 检验用户是否会员，返回用户积分
/// </summary>
public class BaseHandler  : Activity.BaseHandler {

    public BaseHandler()
    {
        //修改请求为post 方式
        base._httpReuqest = base.Context.Request.Form;
    }
    /// <summary>
    /// 校验用户，成功返回积分
    /// </summary>
    public void InitUser()
    {
        //var date = DateTime.Now;
        var code = _httpReuqest["code"];
        var type = _httpReuqest["type"];
        if (string.IsNullOrWhiteSpace(code))
        {
            Error("无效的[Code]值", -1);
        }
        else
        {
            var user = WeixinApi.GetOpenID(code);
            if (user == null)
            {
                Error("用户不存在", -2);
            }
            else if (user.openid == null)
            {
                Error("用户不存在", -2);
            }
            else
            {
                var integal=new BaseLottery();
                switch (type)
                {
                    case "1":
                        if (integal.CheckUser(user.openid))
                            Error("请先注册会员", -3);
                        break;
                    case "2":
                        var result = integal.GetUserIntegral(user.openid);
                        if (result != null)
                            Success(result);
                        break;
                    default:
                        Error("无效类型", -4);
                        break;
                }
            }
        }
    }

    /// <summary>
    /// 返回用户积分
    /// </summary>
    public void GetUserIntegral()
    {
        var openId = _httpReuqest["openId"];
        var integal=new BaseLottery();
        var result=integal.GetUserIntegral(openId);
        if (result != null)
            Success(result);
        else
            Error("会员不存在", -3);
    }

}